package com.wsoft.utils.job;

import com.wsoft.entity.TsJobEntity;
import com.wsoft.entity.TsJobLogEntity;
import com.wsoft.manager.TsJobLogManager;
import com.wsoft.manager.TsJobManager;
import lombok.Getter;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * job 持久化业务
 * @Author z001
 * @Date 2024/10/23 13:53
 */
@Getter
@Service
public class JobRepository {

    @Resource
    private TsJobManager jobManager;

    @Resource
    private TsJobLogManager jobLogManager;

    /**
     * 保存执行记录
     *
     * @param logEntity
     * @param jobEntity
     */
    @Transactional(rollbackFor = Throwable.class)
    public void saveLog(TsJobLogEntity logEntity, TsJobEntity jobEntity) {
        jobLogManager.save(logEntity);

        jobManager.updateById(jobEntity);
    }
}
